﻿using UnityEngine;
using System;
using System.Collections;
using UnityEditor;
using System.Linq;

public class CharViewerMenu : EditorWindow {

	//[MenuItem("OurGame/CharacterViewer")]
	static void Init()
	{
		instance = EditorWindow.GetWindow<CharViewerMenu>();
		if(CharacterViewer.Instance!=null) {
			playerPrefab = CharacterViewer.Instance.playerPrefab;
			enemyPrefab = CharacterViewer.Instance.enemyPrefab;
		}
		else {
			if(playerPrefab==null)
				playerPrefab = Resources.Load ("Prefab/Battle/Character/Assassin_M_BrietraLS_A1") as GameObject;
			if(enemyPrefab==null)
				enemyPrefab = Resources.Load ("Prefab/Battle/Character/Haskin_M_C1") as GameObject;
		}
		playerPrefabOld = playerPrefab;
		enemyPrefabOld = enemyPrefab;
	}

	public static CharViewerMenu instance;
	public static bool turnOffSkillCam;
	public static bool turnOffCamShake;
	public static bool repeatPlay;
	public static GameObject playerPrefab;
	public static GameObject enemyPrefab;

	public static GameObject playerPrefabOld;
	public static GameObject enemyPrefabOld;

	public static Transform[] OriginalCamTrans = new Transform[3];

	void OnGUI() {
		
		if (EditorApplication.isCompiling)
		{
			EditorGUILayout.LabelField("컴파일 중...");
			
			return;
		}
		
		
		//EditorGUILayout.LabelField("기본 세팅");
		//EditorGUI.indentLevel++;
		EditorGUILayout.Space();
		playerPrefab = EditorGUILayout.ObjectField("플레이어 프리팝", playerPrefab, typeof(GameObject), true) as GameObject;
		EditorGUILayout.Space();
		enemyPrefab = EditorGUILayout.ObjectField("적 프리팝", enemyPrefab, typeof(GameObject), true) as GameObject;
		//EditorGUI.indentLevel--;
		
		EditorGUILayout.Space();
//		if(OriginalCamTrans==null || OriginalCamTrans.Length!=3)
//			OriginalCamTrans = new Transform[3];
//		OriginalCamTrans[0] = EditorGUILayout.ObjectField("cam1", OriginalCamTrans[0], typeof(Transform), true) as Transform;
//		OriginalCamTrans[1] = EditorGUILayout.ObjectField("cam2", OriginalCamTrans[1], typeof(Transform), true) as Transform;
//		OriginalCamTrans[2] = EditorGUILayout.ObjectField("cam3", OriginalCamTrans[2], typeof(Transform), true) as Transform;
//		
//		EditorGUILayout.Space();
		
		turnOffSkillCam = EditorGUILayout.ToggleLeft("테이크 카메라 끔", turnOffSkillCam);
		turnOffCamShake = EditorGUILayout.ToggleLeft("카메라 쉐이크 끔", turnOffCamShake);
		EditorGUILayout.Space();
		repeatPlay = EditorGUILayout.ToggleLeft("반복 플레이", repeatPlay);
		//		ShowCheatMenu(ref inst.turnOffSkillCam, "테이크 카메라 끔", () =>
		//		              {
		//			GUI.enabled = true;
		//		});
		//
		//		ShowCheatMenu(ref inst.turnOffSkillCam, "카메라 쉐이크 끔", () =>
		//		              {
		//			GUI.enabled = true;
		//		});
		
		
//		if (GUI.changed)
//		{
//			serializedObject.ApplyModifiedProperties();
//			
//			EditorUtility.SetDirty(inst);
//		}
//		
//		Repaint();

		if(CharacterViewer.Instance!=null) {
			CharacterViewer.Instance.turnOffCamShake=turnOffCamShake;
			CharacterViewer.Instance.turnOffSkillCam=turnOffSkillCam;
			CharacterViewer.Instance.repeatPlay=repeatPlay;
			if(playerPrefab!=null && playerPrefabOld!=playerPrefab) {
				CharacterViewer.Instance.playerPrefab = playerPrefab;
				//CharacterViewer.Instance.CreatePlayer();
			}
			if(enemyPrefab!=null && enemyPrefabOld!=enemyPrefab) {
				CharacterViewer.Instance.enemyPrefab = enemyPrefab;
				//CharacterViewer.Instance.CreateEnemy();
			}
		}
		playerPrefabOld = playerPrefab;
		enemyPrefabOld = enemyPrefab;
	}
}
